﻿using UnityEngine;

namespace Watermelon
{
    [System.Serializable]
    public class Currency
    {
        [SerializeField] Type currencyType;
        public Type CurrencyType => currencyType;

        [SerializeField] Sprite icon;
        public Sprite Icon => icon;

        [SerializeField] GameObject model;
        public GameObject Model => model;

        [SerializeField] bool displayAlways = false;
        public bool DisplayAlways => displayAlways;

        private int amount = 0;
        public int Amount { get => amount; set => amount = value; }

        public string AmountFormatted => CurrenciesHelper.Format(CurrenciesController.Get(currencyType));

        private Pool pool;
        public Pool Pool => pool;

        public void Initialise()
        {
            pool = new Pool(new PoolSettings(currencyType.ToString(), model, 1, true));

            amount = 0;
        }

        public Save GetEmptySave()
        {
            return new Save(currencyType, 0);
        }

        // DO NOT CHANGE ORDER OF THE CURRENCIES AFTER RELEASE. IT CAN BRAKE THE SAVES OF THE GAME!
        public enum Type
        {
            Money = 0,
        }

        [System.Serializable]
        public class Save
        {
            [SerializeField] Type currencyType;
            public Type CurrencyType => currencyType;

            [SerializeField] int amount;
            public int Amount { get => amount; set => amount = value; }

            public Save(Type currencyType, int amount)
            {
                this.currencyType = currencyType;
                this.amount = amount;
            }
        }
    }
}